package com.qdu.mr;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


public class CountMapper
// 1. 实现Mapper父类
    extends Mapper<LongWritable,Text,Text,LongWritable>
{

    // 重写map方法，输入文件的每一行，对应map函数的一次执行
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        // 收到的是一行数据
        // 拆分数据后，按照每个单词一个键值对输出{word,1}
        String[] wordlist = value.toString().split(" ");

        for (String word : wordlist){

            context.write(new Text(word),new LongWritable(1));
        }
    }
}


